package com.grace.controller;

import com.grace.entity.Student;
import com.grace.service.StudentService;
import com.grace.service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/detailStudentServlet")
public class DetailStudentServlet extends HttpServlet {

    StudentService studentService = new StudentServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获得学生的sid
        String sid = request.getParameter("sid");
        //2.调用service查询学生
        Student student = studentService.selectStudentById(Long.parseLong(sid));
        //3.存储学生信息
        request.setAttribute("student", student);
        //4.请求转发
        request.getRequestDispatcher("/detail.jsp").forward(request, response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
